package com.studerb.model;

import java.util.Calendar;

import com.studerb.dao.TimeStampedEntity;

public abstract class Post extends TimeStampedEntity implements Comparable<Post> {
	public final static int SUBJECT_LENGTH = 300;
	public final static int MESSAGE_ID_LENGTH = 100;
	public final static int AUTHOR_LENGTH = 200;
	public final static int FILE_NAME_LENGTH = 200;

	protected String subject;
	protected Calendar datePosted;
	protected Long byteCount;
	protected String author;
	protected NewsGroup newsGroup;
	protected Long articleNumber;
	protected boolean articleDownloaded = false;
	protected String fileName;

	@Override public int compareTo(Post o) {
		return this.getArticleNumber().compareTo(o.getArticleNumber());
	}

	@Override public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Post other = (Post) obj;
		if (newsGroup == null) {
			if (other.newsGroup != null) {
				return false;
			}
		}
		else if (!newsGroup.equals(other.newsGroup)) {
			return false;
		}
		if (subject == null) {
			if (other.subject != null) {
				return false;
			}
		}
		else if (!subject.equals(other.subject)) {
			return false;
		}
		return true;
	}

	public Long getArticleNumber() {
		return articleNumber;
	}

	public String getAuthor() {
		return author;
	}

	public Long getByteCount() {
		return byteCount;
	}

	public Calendar getDatePosted() {
		return datePosted;
	}

	public String getFileName() {
		return fileName;
	}

	public NewsGroup getNewsGroup() {
		return newsGroup;
	}

	public String getSubject() {
		return subject;
	}

	@Override public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (newsGroup == null ? 0 : newsGroup.hashCode());
		result = prime * result + (subject == null ? 0 : subject.hashCode());
		return result;
	}

	public boolean isArticleDownloaded() {
		return articleDownloaded;
	}

	public void setArticleDownloaded(boolean articleDownloaded) {
		this.articleDownloaded = articleDownloaded;
	}

	public void setArticleNumber(Long articleNumber) {
		this.articleNumber = articleNumber;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public void setByteCount(Long byteCount) {
		this.byteCount = byteCount;
	}

	public void setDatePosted(Calendar datePosted) {
		this.datePosted = datePosted;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public void setNewsGroup(NewsGroup newsGroup) {
		this.newsGroup = newsGroup;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}
}
